package etp.client;

import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;

public class Logger extends AbsolutePanel {

	private Label lblText = new Label();
	
	private Image imgLoader = new Image("/images/yellow_loader.gif");
	
	public Logger(){
		
		//Configurando nome de classes
		this.getElement().setClassName("Loader");
		
		//Configurando layout
		
		HorizontalPanel pnlMain = new HorizontalPanel();
		
		this.lblText.getElement().setAttribute("style", "margin-left: 10pt");
		
		pnlMain.add(this.imgLoader);
		pnlMain.add(this.lblText);
		
		this.add(pnlMain);
		
		this.getElement().setAttribute("style", "position: absolute; margin-left: 50%; margin-right: auto;");
	}
	
	public void show(String txt, LoggerType type){
		this.lblText.setText(txt);
		this.imgLoader.setUrl(type.getImage());
		
		this.setVisible(true);
	}
	
	public void center(){
	}
	
	public enum LoggerType{
		
		ERROR("Error", "/images/error.png"),
		WAITING("Waiting", "/images/yellow_loader.gif"),
		SUCCESS("Success", "/images/ok.gif"),
		WARNING("Warning", "/images/warning.png");
		
		private String className;
		
		private String img;
		
		private LoggerType(String className, String image){
			this.className = className;
			this.img = image;
		}
		
		public String getClassName(){
			return this.className;
		}
		
		public String getImage(){
			return this.img;
		}
	}
}
